//
// cocos2d Hello World example
// http://www.cocos2d-iphone.org
//

// Import the interfaces
#import "HelloWorldScene.h"
#import "BackgroundLayer.h"
#import "GameScene.h"

// HelloWorld implementation
@implementation HelloWorld

+(id) scene
{
	// 'scene' is an autorelease object.
	Scene *scene = [Scene node];
	
	// 'layer' is an autorelease object.
	HelloWorld *layer = [HelloWorld node];
	
	// add layer as a child to scene
	[scene addChild: layer];

	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init] )) {
		isTouchEnabled = YES;

		// ask director the the window size
		CGSize size = [[Director sharedDirector] winSize];
		
		//add background layer
		//backgroundLayer = [[BackgroundLayer alloc] init];
		//[self addChild:backgroundLayer];
		
		Sprite* sp = [Sprite spriteWithFile:@"coverimg.jpg"];
		[sp setPosition:CGPointMake(size.width/2,size.height/2)];
		[self addChild:sp];
		//add sprite to layer
		
////////  add menuitem layer  /////
		[self addChild:[[MenuLayer alloc] init]];
		
		//boxSprite = [Sprite spriteWithFile:@"sheep_eat.gif"];
		//[boxSprite setPosition:CGPointMake(20,size.height/2)];
		//[self addChild: boxSprite];
	}
	return self;
}

-(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *) event
{
	UITouch *touch = [touches anyObject];
	CGPoint p = [touch locationInView:[touch view]];
	
	[boxSprite runAction:[MoveTo actionWithDuration:1 position:[[Director sharedDirector] convertCoordinate:p]]];
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	[boxSprite dealloc];
	[super dealloc];
}
@end


#pragma mark Menu--MenuItem set
@implementation MenuLayer

- (id) init
{
	if( (self=[super init]) )
	{
		MenuItem *itemStart = [MenuItemFont itemFromString:@"Start Game" target:self selector:@selector(startMenu:) ];
		MenuItem *itemScore = [MenuItemFont itemFromString:@"Score" target:self selector:@selector(scoreMenu:) ];
		MenuItem *itemOption = [MenuItemFont itemFromString:@"Option" target:self selector:@selector(optionMenu:) ];
		MenuItem *itemAboutUs = [MenuItemFont itemFromString:@"AboutUs" target:self selector:@selector(aboutUsMenu:) ];
		MenuItem *itemExit = [MenuItemFont itemFromString:@"Exit" target:self selector:@selector(exitMenu:) ];
		
		menu = [Menu menuWithItems:itemStart,itemScore,itemOption,itemAboutUs,itemExit,nil];
		[menu alignItemsVertically];
		[self addChild:menu];
	}
	return self;
}

- (void)startMenu:(id) sender
{
	GameScene *gameSence = [GameScene node];
	[[Director sharedDirector] replaceScene:gameSence];
}

- (void)scoreMenu:(id) sender
{
	
}

- (void)optionMenu:(id) sender
{
	
}

- (void)aboutUsMenu:(id) sender
{
	
}

-(void)exitMenu:(id) sender
{
	[[Director sharedDirector] end];
}

- (void) dealloc
{
	[super dealloc];
}

@end

